import axios from 'axios';
import React from 'react';
import {message,notification} from 'antd';

//axios全局配置
axios.interceptors.request.use(function (config) {
    config.headers = {
        'Accept': "application/json, text/plain, */*",
        'Content-Type': "application/x-www-form-urlencoded",
        'Authorization': localStorage.getItem('token') ? localStorage.getItem('token') : ''
    };
    config.timeout = 2000;
    // config.baseURL = '/api';
    config.baseURL = 'http://123.60.208.83:8099';
    return config;
});
axios.interceptors.response.use (
  response => {{
    if (response.headers.authorization) {
      localStorage.setItem('token',response.headers.authorization)
    } 
    return response.data;
  }},
  error => {
    console.log(error);
    if (error.message.includes('403')) {
      notification['error']({
        message:'权限不足',
        description:'您的权限无法完成此操作，请联系管理员或超级管理员'
      })
    }
    if(error.message.includes('timeout')){
      console.log(error);
      notification['error']({
        message:'网络错误',
        description:'网络连接超时或服务器关闭'
      })
      return Promise.reject(error)
    }
    return Promise.reject(error)
  }
    // 对响应数据做点什么
    // response.status !== 204 && (response.data.msg = (typeof response.data.msg === 'array') ? response.data.msg[0] : response.data.msg);
    
    
);

export default axios;